package com.qhy.wxpay.config;

import com.qhy.wxpay.handler.ApiTokenHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/*
 * @Author qiuhongyu
 * @Description 可以使用自定义类扩展MVC的功能
 * @Date 20:11 2021/9/20
 * @Param
 * @return
 **/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public ApiTokenHandlerInterceptor getApiTokenHandlerInterceptor() {
        return new ApiTokenHandlerInterceptor();
    }


    /*
     * @Author qiuhongyu
     * @Description 允许接口跨域访问请求
     * @Date 20:11 2021/6/18
     * @Param [registry]
     * @return void
     **/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH");
    }


    /**
     * @return void
     * @Author qiuhongyu
     * @Description 拦截器注册
     * @Date 20:11 2021/5/19
     * @Param [registry]
     **/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 2：app接口处理
        registry.addInterceptor(getApiTokenHandlerInterceptor()).addPathPatterns("/app/**");
    }

}